package com.gdust.gkyx.sys.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gdust.gkyx.common.result.Result;
import com.gdust.gkyx.model.sys.RegionWare;
import com.gdust.gkyx.sys.service.RegionWareService;
import com.gdust.gkyx.vo.sys.RegionWareQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName: RegionWareController
 * Package: com.gdust.gkyx.sys.controller
 * Description:参考前端src >api>sys > regionWare.js开发接口
 *
 * @Author syun
 * @Create 2025/1/24 13:54
 * @Version 1.0
 */
@Api(tags = "开通区域接口")
@RestController
@RequestMapping("/admin/sys/regionWare")
//@CrossOrigin
public class RegionWareController {
    //注入城市仓库关联表的service
    @Autowired
    private RegionWareService regionWareService;

    /**
     *     //分页查询开通区域列表
     * //    url: `${api_name}/${page}/${limit}`,
     * //    method: 'get',
     * //    params: searchObj
     * @param page 当前页
     * @param limit 每页记录数
     * @param regionWareQueryVo 分页条件对象
     * @return
     */
    @ApiOperation("分页查询开通区域列表")
    @GetMapping("{page}/{limit}")
    public Result list(@PathVariable Long page,
                       @PathVariable Long limit,
                       RegionWareQueryVo regionWareQueryVo) {
        //1 创建page对象，传递当前页和每页记录数
        // current：当前页
        // limit: 每页显示记录数
        Page<RegionWare> pageParam = new Page<>(page,limit);
        //2 自定义方法：调用service方法实现条件分页查询，返回分页对象
        //自定义方法：分页查询开通区域列表
        IPage<RegionWare> pageModel = regionWareService.selectPageRegionWare(pageParam,regionWareQueryVo);
        return Result.ok(pageModel);
    }


    /**
     *  //添加开通区域
     * //    url: `${api_name}/save`,
     * //    method: 'post',
     * //    data: role
     * @param regionWare 开通区域对象，包含：开通区域和区域名称
     * @return
     */
    @ApiOperation("添加开通区域")
    @PostMapping("save")
    public Result addRegionWare(@RequestBody RegionWare regionWare) {
        //自定义方法：添加开通区域
        regionWareService.saveRegionWare(regionWare);
        return Result.ok(null);
    }

    /**
     *     //删除开通区域
     * //    url: `${api_name}/remove/${id}`,
     * //    method: 'delete'
     * @param id 区域id
     * @return
     */
    @ApiOperation("删除开通区域")
    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable Long id) {
        //自定义方法：删除开通区域
        regionWareService.removeById(id);
        return Result.ok(null);
    }

    /**
     *     //取消开通区域
     * //    url: `${api_name}/updateStatus/${id}/${status}`,
     * //    method: 'post'
     * @param id 区域id
     * @param status 状态（0：未开通 1：已开通）
     * @return
     */
    @ApiOperation("取消开通区域")
    @PostMapping("updateStatus/{id}/{status}")
    public Result updateStatus(@PathVariable Long id,
                               @PathVariable Integer status) {
        //自定义方法：取消开通区域
        regionWareService.updateStatus(id,status);
        return Result.ok(null);
    }


}
